<h3><center>DAFTAR PRODUK</center></h3>
<a><center>
<?php
session_start();
include 'fungsi.php';


if($_POST['btnaction']=="Edit")
{
   $id = $_POST['id'];
   $page = "editproduk.php?id=".$id;
   $hasil = new fungsi();
   $masuk = $hasil->redirectPage($page);
   echo $masuk;
}

if($_POST['btnaction']=="Hapus")
{
   $id = $_POST['id'];
   $page = "deleteproduk.php?id=".$id;
   $hasil = new fungsi();
   $masuk = $hasil->redirectPage($page);
   echo $masuk;
}

$log = $_GET['log'];
//if($log=='in'){
	$user = $_SESSION['username'];
	
	if(!isset($user)){ //|| $log!="in"){
		die("Anda belum Login, silahkan kembali ke halaman awal anda");
		
		/*$page = "home-guess.php";
		$keluar = $hasil->redirectPage($page);
		echo $keluar;*/
		
	}

	if($_SESSION['hak_akses']!="2"){
		die("!!");
	}
mysql_connect("localhost","root","");
  mysql_select_db("ngalam");
  $dataPerPage = 5;
$query   = "SELECT COUNT(*) AS nama FROM produk";
$hasil1  = mysql_query($query);
$data1   = mysql_fetch_array($hasil1);

$Nama = $data1['nama'];

$jumPage = ceil($Nama/$dataPerPage);


if ($noPage > 1) echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage-1)."'>&lt;&lt; Prev</a>";

for($page = 1; $page <= $jumPage; $page++)
{
         if ((($page >= $noPage - 3) && ($page <= $noPage + 3)) || ($page == 1) || ($page == $jumPage)) 
         {   
            if (($showPage == 1) && ($page != 2))  echo "..."; 
            if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
            if ($page == $noPage) echo " <b>".$page."</b> ";
            else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a> ";
            $showPage = $page;          
         }
}

if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage+1)."'>Next &gt;&gt;</a>";

?>
</center>
</a>
<table class="tabel table-condensed "  width="500"  cellpadding="5" cellspacing="1" background="magenta" >
	

<?php

  mysql_connect("localhost","root","");
  mysql_select_db("ngalam");
  $dataPerPage = 5;

if(isset($_GET['page']))
{
    $noPage = $_GET['page'];
} 
else $noPage = 1;

$offset = ($noPage - 1) * $dataPerPage;


  $sql = "select * from produk LIMIT $offset, $dataPerPage";
  $hasil = mysql_query($sql);
  
  while($data=mysql_fetch_array($hasil)){
  $nama = $data['nama_produk'];
  $deskripsi = $data['deskripsi_produk'];
  $gambar = $data['gambar'];
  $id = $data['kode_produk'];
  echo '<form method="POST" action="">
		<tr>
			
			<td>
			<a align="left" name="judul"><img src='.$gambar.' width="200px" height=></a>
			</td>
			<td>
			<font size=5 name="nama">'.$nama.'</font>
		<p  class="span10" style="color:black" align="justify" name="deskripsi" ><font size=2>'.$deskripsi.'</font></p>
			</td>
			<td>
			
				<input type="hidden" name="id" value="'.$id.'">
				<input type="submit" name="btnaction" style="width:70" value="Edit">
			</td>
			<td>
				<input type="submit" name="btnaction" style="width:70" value="Hapus">
			</td>
		
	</tr>
	</form>';
	
  
		  
		}
?>  


</table>